package com.harmontronics.hanma.paas.paas.domain.app.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.harmontronics.hanma.paas.paas.domain.app.repository.persistence.HttpServiceSettingRepository;
import com.harmontronics.hanma.paas.paas.domain.app.entity.HttpServiceSetting;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.harmontronics.hanma.paas.paas.common.PageBase;

import com.harmontronics.hanma.paas.paas.domain.app.repository.mapper.HttpServiceSettingMapper;
import com.harmontronics.hanma.paas.paas.domain.app.repository.po.HttpServiceSettingPO;
import java.util.List;

@Service("httpServiceSettingService")
public class HttpServiceSettingService {

    @Autowired
    private HttpServiceSettingRepository httpServiceSettingRepository;


    public HttpServiceSetting findById( Long httpServiceId) {
            HttpServiceSettingPO po = httpServiceSettingRepository.getById(httpServiceId);
        return BeanUtil.toBean(po,HttpServiceSetting. class);
    }

    public void save(HttpServiceSetting httpServiceSetting) {
            HttpServiceSettingPO po = BeanUtil.toBean(httpServiceSetting,HttpServiceSettingPO.class);
            httpServiceSettingRepository.save(po);
    }

    public void update(HttpServiceSetting httpServiceSetting) {
            HttpServiceSettingPO po = BeanUtil.toBean(httpServiceSetting,HttpServiceSettingPO.class);
            httpServiceSettingRepository.updateById(po);
    }

    public void remove(List<Long> ids) {
            httpServiceSettingRepository.removeByIds(ids);
    }

    public List<HttpServiceSetting> getList() {
        List<HttpServiceSettingPO> pos = httpServiceSettingRepository.list();
        return Convert.toList(HttpServiceSetting. class,pos);
    }

    public PageBase<HttpServiceSetting> getList(int pageNo, int pageSize) {
        Page<HttpServiceSettingPO> page = new Page<>(pageNo, pageSize);
        IPage<HttpServiceSettingPO> resultPage =
                    httpServiceSettingRepository.selectPage(Wrappers.emptyWrapper(), page);
        return PageBase.from(resultPage,HttpServiceSetting. class);
    }

}